export default {

  namespaced: true,
  state: JSON.parse(localStorage.getItem("vuex_count")) || {
    num: 0,
  },

  getters: {
    doubleNum(state) {
      return state.num * 2;
    },
  },

  mutations: {
    increment(state) {
      state.num++;
      localStorage.setItem("vuex_count", JSON.stringify(state));
    },

    incrementN(state, { n }) {
      state.num += n;
      localStorage.setItem("vuex_count", JSON.stringify(state));
    },
  },

  actions: {
    incrementWait({ commit }) {
      setTimeout(() => {
        commit("increment");
      }, 1000);
    },

    incrementNWait({ commit }, payload) {
      setTimeout(() => {
        commit("incrementN", payload);
      }, 1000);
    },
  },
};
